package com.lottery.controller.pc28.wealthController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lottery.dto.PageDto;
import com.lottery.service.pc28.JedisClient;
import com.lottery.service.pc28.accoutService.ManualCustomerservice;
import com.lottery.service.pc28.wealthService.*;
import com.lottery.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

@Controller
public class WealthContller {

	@Autowired
	private ManualCustomerservice manualCustomerservice;

	@Resource
	public QueryAccountService queryAccountService;

	@Resource
	public BankCardService bankCardService;

	@Resource
	public RechargeService rechargeService;

	@Resource
	public WithdrawalsService withdrawalsService;

	@Resource
	public HistoryService historyService;

	@Resource
	public JedisClient jedisClient;

	// 日志
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	/**
	 * 查询提现卡接口
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/Withdrawals", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String Withdrawals(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");
			return withdrawalsService.selectWithdhall(userId);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****Withdrawals error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 财富额度查询
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/queryWealth", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String queryWealth(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");
			return queryAccountService.selectAccountConfig(userId);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****queryWealth error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 财富记录查询
	 * 
	 * @throws UnsupportedEncodingException
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/queryRecord", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String queryRecord(HttpServletRequest request) throws UnsupportedEncodingException {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			Integer userId = obj.getInteger("userId");
			Integer pageSize = obj.getInteger("pageSize");
			if (pageSize == null) {
				pageSize = 5;
			}
			Integer pageNow = obj.getInteger("pageNow");
			if (pageNow == null) {
				pageNow = 1;
			}
			Integer types = obj.getInteger("types");
			if (types == null) {
				types = 1;
			}
			PageDto pageDto = new PageDto();
			pageDto.setPageNow(pageNow);
			pageDto.setPageSize(pageSize);
			Integer startPage = pageDto.getstartPage();
			return queryAccountService.selectWealthRecord(userId, types, startPage, pageSize);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****queryRecord error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 查询当日所有流水
	 * 
	 * @throws UnsupportedEncodingException
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/queryDayRecord", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String queryDayRecord(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");
			return queryAccountService.queryDailyBettingSummary(userId);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****queryDayRecord error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}

		return jObject.toJSONString();
	}

	/**
	 * 判断有没有实名认证
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/Certification", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String Certification(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");
			return bankCardService.Certification(userId);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****Certification error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/*
	 * 根据帐户ID查询银行卡
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/queryBankCard", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String queryBankCard(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");

			return bankCardService.selectBankCardByAccount_id(userId);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****queryBankCard error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/*
	 * 根据帐户ID得到用户真实姓名和电话号码
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/queryUserName", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String queryUserName(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");
			return bankCardService.getUsername(userId);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****queryUserName error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/*
	 * 发送短信验证
	 */
	@CrossOrigin
	@RequestMapping("/api/wealth/SendSMS")
	@ResponseBody
	public String SendSMS(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");
			return bankCardService.SendSMS(userId);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****SendSMS error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/*
	 * 添加银行卡到数据库
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/addBankCard", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String addBankCard(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			String bankcardusername = obj.getString("name");
			int userId = obj.getInteger("userId");
			String code = obj.getString("code");
			String bankcard_number = obj.getString("bankcardNumber");
			return bankCardService.insertBankcard(userId, code, bankcard_number, bankcardusername);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****addBankCard error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/*
	 * 删除用户银行卡
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/deleteBankCard", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String deleteBankCard(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");
			String bankcardNumber = obj.getString("bankcardNumber");
			return bankCardService.deleteBankcard(userId, bankcardNumber);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****deleteBankCard error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/*
	 * 版本检查
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/public/Checked", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String Checked(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			JSONObject obj = JSONObject.parseObject(body);
			String version = obj.getString("version");
			String deviceType = obj.getString("deviceType") == null ? "android" : obj.getString("deviceType");
			return historyService.selectHistoryService(version, deviceType);
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****Checked error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 获取彩钻数量接口
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/clientgetcash", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" }) // 客服端
	@ResponseBody
	public String clientgetcash(HttpServletRequest request) throws IOException {
		JSONObject jObject = new JSONObject();
		String body = readHttpBody(request);
		// 日志
		logger.info("********clientgetcash in********:" + body);
		try {
			JSONObject obj = JSON.parseObject(body);
			int userId = obj.getInteger("userId");

			int withdrawDiamond = obj.getInteger("withdrawDiamond");
			int flag = 1;
			logger.info("userId:{},rechargeAmount:{}, flag:{}", userId, withdrawDiamond, flag);
			String getDiamondNum = manualCustomerservice.clientgetcash(userId, withdrawDiamond);
			logger.info("********clientgetcash out********:" + getDiamondNum);
			return getDiamondNum;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("*****clientgetcash error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 自助提现接口
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/autocash", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" }) // 客服端
	@ResponseBody
	public String autoCash(HttpServletRequest request) throws IOException {
		String body = readHttpBody(request);
		JSONObject jObject = new JSONObject();
		// 日志
		logger.info("********autoCash in********:" + body);
		try {
			JSONObject obj = JSON.parseObject(body);
			int userId = obj.getInteger("userId");
			int amount = obj.getInteger("amount");
			int withdrawDiamond = obj.getInteger("withdrawDiamond");
			int cashType = obj.getInteger("cashType");
			String cashAccout = obj.getString("cashAccout");
			String phoneNum = obj.getString("phoneNum");
			String code = obj.getString("code");
			String cashName = obj.getString("cashName") == null ? "" : obj.getString("cashName");
			String customerRecharge = manualCustomerservice.autoCash(userId, cashType, withdrawDiamond, cashAccout,
					cashName, amount, phoneNum, code);
			logger.info("********autoCash out********:{}" + customerRecharge);
			return customerRecharge;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("*****autoCash error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 客户提现流水接口
	 * 
	 * @throws UnsupportedEncodingException
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/cashtransaction", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String cashTransaction(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			logger.info("********cashTransaction in********:" + body);
			JSONObject obj = JSONObject.parseObject(body);
			int userId = obj.getInteger("userId");
			int pageNum = obj.getInteger("pageNum");
			int pageSize = obj.getInteger("pageSize");
			String result = queryAccountService.queryOrderStatus(userId, pageNum, pageSize);
			logger.info("********cashTransaction out********：{}", result);
			return result;
		} catch (IOException e) {
			e.printStackTrace();
			logger.error("*****orderDetails error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 修改订单状态为成功或者失败
	 */
	@CrossOrigin
	@RequestMapping(value = "/api2/wealth/updateorder", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" }) // 客服端
	@ResponseBody
	public String updateorder(HttpServletRequest request) throws IOException {
		String body = readHttpBody(request);
		JSONObject jObject = new JSONObject();

		try {
			logger.info("********updateordersuccess in********:" + body);
			String hostAddr = request.getRemoteAddr();
			logger.info("hostAddr: " + hostAddr);

			JSONObject obj = JSON.parseObject(body);
			String orderId = obj.getString("orderId");
			int state = obj.getInteger("state");
			int serverId = obj.getInteger("serverId");
			String remark = obj.getString("remark") == null ? "" : obj.getString("remark");
			remark = remark + ";" + serverId;
			logger.info("orderId:{},state:{}", orderId, state);
			String updateState = manualCustomerservice.updateState(orderId, state, remark);
			logger.info("********updateordersuccess out********:" + updateState);
			return updateState;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("*****cashTransaction error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();

	}

	/**
	 * 修改订单状态为失败
	 */
	// @RequestMapping(value = "/updateorderfail", method = RequestMethod.POST,
	// produces = {
	// "application/json;charset=UTF-8" }) // 客服端
	// @ResponseBody
	// public String updateorderfail(HttpServletRequest request) throws
	// IOException
	// {
	// String body = readHttpBody(request);
	// logger.info("********updateorderfail in********:" + body);
	// String hostAddr = request.getRemoteAddr();
	// logger.info("hostAddr: " + hostAddr);
	//
	// JSONObject obj = JSON.parseObject(body);
	// String orderId = obj.getString("id");
	// int state = 2; // 失败
	// String remark = obj.getString("discribe") == null ? "" :
	// obj.getString("discribe");
	// logger.info("orderId:{},state:{},remark:{}", orderId, state, remark);
	// String updateState = manualCustomerservice.updateState(orderId, state,
	// remark, hostAddr, null, null, null);
	// logger.info("********updateorderfail out********:" + updateState);
	// return updateState;
	// }

	// @RequestMapping(value = "/updateorderfail", method = RequestMethod.POST,
	// produces = {
	// "application/json;charset=UTF-8" }) // 客服端
	// @ResponseBody
	// public String updateorderfail(HttpServletRequest request) throws
	// IOException {
	// String body = readHttpBody(request);
	// logger.info("********updateorderfail in********:" + body);
	// String hostAddr = request.getRemoteAddr();
	// logger.info("hostAddr: " + hostAddr);
	//
	// JSONObject obj = JSON.parseObject(body);
	// String orderId = obj.getString("id");
	// int state = 2; // 失败
	// String remark = obj.getString("discribe") == null ? "" :
	// obj.getString("discribe");
	// logger.info("orderId:{},state:{},remark:{}", orderId, state, remark);
	// String updateState = manualCustomerservice.updateState(orderId, state,
	// remark, hostAddr, null, null, null);
	// logger.info("********updateorderfail out********:" + updateState);
	// return updateState;
	// }
	// /**
	// * 修改订单状态为未知
	// */
	// @RequestMapping(value = "/updateorderunkown", method =
	// RequestMethod.POST,
	// produces = {
	// "application/json;charset=UTF-8" }) // 客服端
	// @ResponseBody
	// public String updateorderunkown(HttpServletRequest request) throws
	// IOException {
	// String body = readHttpBody(request);
	// logger.info("********updateorderunkown in********:" + body);
	// String hostAddr = request.getRemoteAddr();
	// logger.info("hostAddr: " + hostAddr);
	//
	// JSONObject obj = JSON.parseObject(body);
	// String orderId = obj.getString("id");
	// int state = 3; // 未知
	// String remark = ""; // obj.getString("remark") == null ? "" :
	// obj.getString("remark");
	// logger.info("orderId:{},state:{}", orderId, state);
	// String updateState = manualCustomerservice.updateState(orderId, state,
	// remark, hostAddr, null, null, null);
	// logger.info("********updateorderunkown out********:" + updateState);
	// return updateState;
	// }

	// /**
	// * 修改订单状态为未知
	// */
	// @RequestMapping(value = "/updateorderunkown", method =
	// RequestMethod.POST, produces = {
	// "application/json;charset=UTF-8" }) // 客服端
	// @ResponseBody
	// public String updateorderunkown(HttpServletRequest request) throws
	// IOException {
	// String body = readHttpBody(request);
	// logger.info("********updateorderunkown in********:" + body);
	// String hostAddr = request.getRemoteAddr();
	// logger.info("hostAddr: " + hostAddr);
	//
	// JSONObject obj = JSON.parseObject(body);
	// String orderId = obj.getString("id");
	// int state = 3; // 未知
	// String remark = ""; // obj.getString("remark") == null ? "" :
	// obj.getString("remark");
	// logger.info("orderId:{},state:{}", orderId, state);
	// String updateState = manualCustomerservice.updateState(orderId, state,
	// remark, hostAddr, null, null, null);
	// logger.info("********updateorderunkown out********:" + updateState);
	// return updateState;
	// }

	/**
	 * 获取未处理的流水
	 */
	@RequestMapping(value = "/api/wealth/public/getorders", produces = { "application/json;charset=UTF-8" })
	@ResponseBody
	public String getOrders(HttpServletRequest request) throws IOException {
		JSONObject jObject = new JSONObject();
		try {
			logger.info("********getorders in********");
			String hostAddr = request.getRemoteAddr();
			logger.info("hostAddr: " + hostAddr);

			String orders = manualCustomerservice.getOrders(hostAddr);
			logger.info("********getorders out********:" + orders);
			return orders;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("*****getOrders error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 获取未知状态的流水
	 */
	@CrossOrigin
	@RequestMapping(value = "/api2/wealth/getunkownorders", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" })
	@ResponseBody
	public String getunkownorders(HttpServletRequest request) throws IOException {
		JSONObject jObject = new JSONObject();
		try {
			logger.info("********getorders new in********");
			String hostAddr = request.getRemoteAddr();
			logger.info("hostAddr: " + hostAddr);

			String orders = manualCustomerservice.getUnknowOrders(hostAddr);
			logger.info("********getorders out********:" + orders);
			return orders;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("*****getunkownorders error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();

	}

	/**
	 * 客户总提现和充值情况
	 */
	@CrossOrigin
	@RequestMapping(value = "/api2/wealth/totelDrawAndRecharge", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" }) // 客服端
	@ResponseBody
	private String totelDrawAndRecharge(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			logger.info("********withdrawwealth in********:" + body);
			JSONObject obj = JSON.parseObject(body);
			int userId = obj.getInteger("userId");
			String startTime = obj.getString("startTime") == null ? "19700101010100" : obj.getString("startTime");
			String endTime = obj.getString("endTime") == null ? DateUtil.getFormatDate("yyyyMMddHHmmss")
					: obj.getString("endTime");
			String result = queryAccountService.totalWithDrawWealth(userId, startTime, endTime);

			return result;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("*****totelDrawAndRecharge error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();

	}

	/**
	 * 客服端提现查询
	 */
	@CrossOrigin
	@RequestMapping(value = "/api2/wealth/querywithdrow", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" }) // 客服端
	@ResponseBody
	private String withDrowQuery(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			logger.info("********withdrowquery in********:" + body);
			JSONObject obj = JSON.parseObject(body);
			int userId = obj.getInteger("userId") == null ? 0 : obj.getInteger("userId");
			int pageNum = obj.getInteger("pageNum");
			int pageSize = obj.getInteger("pageSize");
			String startTime = obj.getString("startTime") == null ? "19700101010100" : obj.getString("startTime");
			String endTime = obj.getString("endTime") == null ? DateUtil.getFormatDate("yyyyMMddHHmmss")
					: obj.getString("endTime");
			String result = queryAccountService.withDrowQuery(userId, startTime, endTime, pageNum, pageSize);
			logger.info("********withdrowquery out********:" + result);

			return result;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("*****withDrowQuery error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();

	}

	/**
	 * 客服端充值查询
	 */
	@CrossOrigin
	@RequestMapping(value = "/api2/wealth/queryrecharge", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" }) // 客服端
	@ResponseBody
	private String chargeQuery(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			logger.info("********withdrowquery in********:" + body);
			JSONObject obj = JSON.parseObject(body);
			int userId = obj.getInteger("userId") == null ? 0 : obj.getInteger("userId");
			int pageNum = obj.getInteger("pageNum");
			int pageSize = obj.getInteger("pageSize");
			String startTime = obj.getString("startTime") == null ? "19700101010100" : obj.getString("startTime");
			String endTime = obj.getString("endTime") == null ? DateUtil.getFormatDate("yyyyMMddHHmmss")
					: obj.getString("endTime");
			String result = queryAccountService.rechargeQuery(userId, startTime, endTime, pageNum, pageSize);
			logger.info("********withdrowquery out********:" + result);

			return result;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("*****chargeQuery error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();

	}

	/**
	 * 自助充值url
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/getRechargeUrl", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" }) // 客服端
	@ResponseBody
	private String getRechargeUrl(HttpServletRequest request) {
		JSONObject jObject = new JSONObject();
		String body = "";
		try {
			body = readHttpBody(request);
			logger.info("********getRechargeUrl in********:" + body);
			String result = queryAccountService.getRechargeUrl();
			logger.info("********getRechargeUrl out********:" + result);

			return result;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("*****getRechargeUrl error******:", e);
			jObject.put("result", "1");
			jObject.put("msg", "失败");
		}
		return jObject.toJSONString();
	}

	/**
	 * 获取充值提现信息
	 */
	@CrossOrigin
	@RequestMapping(value = "/api/wealth/rechargeHint", method = RequestMethod.POST, produces = {
			"application/json;charset=UTF-8" }) // 客服端
	@ResponseBody
	private String rechargeHint(HttpServletRequest request) {
		String body = "";
		try {
			body = readHttpBody(request);
		} catch (IOException e) {
			logger.error("*****rechargeHint error******:", e);
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info("********rechargeHint in********:" + body);
		JSONObject obj = JSON.parseObject(body);
		int userId = obj.getInteger("userId") == null ? 0 : obj.getInteger("userId");
		String result = queryAccountService.rechargeHint(userId);
		logger.info("********rechargeHint out********:" + result);

		return result;
	}

	/**
	 * 解析json
	 * 
	 * @param request
	 * @return
	 * @throws IOException
	 */
	private String readHttpBody(HttpServletRequest request) throws IOException {

		// 读取input流
		/*
		 * BufferedReader br = new BufferedReader( new
		 * InputStreamReader((ServletInputStream) request.getInputStream(),
		 * "utf-8")); StringBuffer sb = new StringBuffer(""); String temp; while
		 * ((temp = br.readLine()) != null) { sb.append(temp); } br.close();
		 * return sb.toString();
		 */

		String attribute = (String) request.getAttribute("json");
		return attribute;
	}

}
